import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {AuditQuery, AuditVO, MapDataVo} from "@/api/audit/types";
import {UserQuery} from "@/api/user/types";

/**
 * 标准核销单分页数据
 *
 * @param queryParams
 */
export function getAuditPage(
	queryParams: AuditQuery
): AxiosPromise<PageResult<[]>> {
	return request({
		url: '/api/v1/audit/page',
		method: 'get',
		params: queryParams
	});
}

/**
 * 未归档核销单分页数据
 *
 * @param queryParams
 */
export function getAllAuditPage(
	queryParams: AuditQuery
): AxiosPromise<PageResult<[]>> {
	return request({
		url: '/api/v1/audit/pageAll',
		method: 'get',
		params: queryParams
	});
}

/**
 * 导入标准账单
 *
 * @param file
 */
export function importBill(platform: string, file: File) {
	const formData = new FormData();
	formData.append('file', file);
	return request({
		url: '/api/v1/bill/sourceImport',
		method: 'post',
		params: { platform: platform },
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	});
}

/**
 * 获取用户表单详情
 *
 * @param userId
 */
export function getAuditVO(id: any): AxiosPromise<AuditVO> {
	return request({
		url: '/api/v1/audit/' + id,
		method: 'get'
	});
}

/**
 * 获取获取原始订单详情
 *
 * @param linkNo
 */
export function getOrderDetail(linkNo: string) {
	return request({
		url: '/api/v1/audit/orderDetail/' + linkNo,
		method: 'get'
	});
}

/**
 * 获取获取原始账单详情
 *
 * @param userId
 */
export function getBillDetail(linkNo: string) {
	return request({
		url: '/api/v1/audit/bill/' + linkNo,
		method: 'get'
	});
}

/**
 * 获取获取原始账单详情
 *
 * @param userId
 */
export function getAuditList(historyAuditQueryList: any): AxiosPromise<[]> {
	return request({
		url: '/api/v1/audit/auditList',
		method: 'post',
		data: historyAuditQueryList,
	});
}

/**
 * 导出待审核核销单
 *
 * @param queryParams
 * @returns
 */
export function exportAudit(ids: any, queryParams: AuditQuery) {
	if (ids.length > 0) {
		return request({
			url: '/api/v1/audit/_export',
			method: 'post',
			data: {'ids': ids},
			responseType: 'arraybuffer'
		});
	}else{
		return request({
			url: '/api/v1/audit/_export',
			method: 'get',
			params: queryParams,
			responseType: 'arraybuffer'
		});
	}
}

/**
 * 导入用户
 *
 * @param file
 */
export function importAudit(file: File) {
	const formData = new FormData();
	formData.append('file', file);
	return request({
		url: '/api/v1/audit/_import',
		method: 'post',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	});
}

export function reBill(ids: any) {
	return request({
		url: '/api/v1/audit/reBill',
		method: 'post',
		data: {'ids': ids},
	});
}

/**
 * 获取获取个人已办未归档和个人归档原始订单详情
 *
 * @param doneId
 */
export function getDoneAuditOrderDetail(doneId) {
	return request({
		url: '/api/v1/doneAudit/order/' + doneId,
		method: 'get'
	});
}

/**
 * 获取获取个人已办未归档和个人归档原始账单详情
 *
 * @param doneId
 */
export function getDoneAuditBillDetail(doneId) {
	return request({
		url: '/api/v1/doneAudit/bill/' + doneId,
		method: 'get'
	});
}

/**
 * 获取获取已归档核销单的原始订单详情
 *
 * @param linkNo
 * @param fileAuditId
 */
export function getFileAuditOrderDetail(linkNo, fileAuditId) {
	return request({
		url: '/api/v1/fileAudit/order/' + linkNo + '/' + fileAuditId,
		method: 'get'
	});
}

/**
 * 获取获取已归档核销单的原始账单详情
 *
 * @param linkNo
 * @param fileAuditId
 */
export function getFileAuditBillDetail(linkNo, fileAuditId) {
	return request({
		url: '/api/v1/fileAudit/bill/' + linkNo + '/' + fileAuditId,
		method: 'get'
	});
}
